package com.numberone.master.modules.orders.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.numberone.master.common.config.Global;
import com.numberone.master.common.persistence.Page;
import com.numberone.master.common.web.BaseController;
import com.numberone.master.common.utils.StringUtils;
import com.numberone.master.modules.orders.entity.ShareOrder;
import com.numberone.master.modules.orders.service.ShareOrderService;
import com.numberone.master.modules.sys.utils.UserUtils;

/**
 * 分润Controller
 * @author ck
 * @version 2018-03-27
 */
@Controller
@RequestMapping(value = "${adminPath}/orders/shareOrder")
public class ShareOrderController extends BaseController {

	@Autowired
	private ShareOrderService shareOrderService;

	 /**
     * 根据id查询一条数据
     * @param id
     * @return
     */
	@ModelAttribute
	public ShareOrder get(@RequestParam(required=false) String id) {
		ShareOrder entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = shareOrderService.get(id);
		}
		if (entity == null){
			entity = new ShareOrder();
		}
		return entity;
	}

	 /**
     * list列表
     * @param shareOrder
     * @param request
     * @param response
     * @param model
     * @return
     */
	@RequiresPermissions("orders:shareOrder:list")
	@RequestMapping(value = {"list", ""})
	public String list(ShareOrder shareOrder, HttpServletRequest request, HttpServletResponse response, Model model) {
		String id = UserUtils.getUser().getOffice().getId();
		if(!"1".equals(id)){
			shareOrder.setOfficeId(id);
		}
		Page<ShareOrder> page = shareOrderService.findPage(new Page<ShareOrder>(request, response), shareOrder); 
		model.addAttribute("page", page);
		return "modules/orders/shareOrderList";
	}

}